import { post } from '@/request/http'
// import { toString } from '@/utils/utils'
import store from '@/store'
import { setMd5 } from '@/utils/utils'

// 车队创建维护

// 获取查询列表  车队创建维护
export const queryUseres = ({ cmpName, usrName, PageIndex, PageSize }) =>
  post('/FTKJWLHYPT/system/querySysFleetUser', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cmpName,
          usrName,
          fltUuid: store.state.user.FLT_UUID_DX_H
        }
      },
      Orderby: {},
      PageIndex: {
        FTKJWLHYPT: PageIndex
      },
      PageSize: {
        FTKJWLHYPT: PageSize
      }
    }
  })
//新增供应商用户
export const addSysFleetUser = ({
  cmpId, //必填
  usrCode, //必填
  usrName, //必填
  usrStatus, //必填
  creator, //必填
  usrCellphone,
  usrEmail,
  remark
}) =>
  post('FTKJWLHYPT/system/addSysFleetUser', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cmpId,
          usrCode,
          usrName,
          usrCellphone,
          usrEmail,
          usrStatus,
          creator,
          remark,
          fltUuid: store.state.user.FLT_UUID_DX_H
        }
      }
    }
  })
//删除用户
export const delSysFleetUser = ({
  uuid,
  version //必填
}) =>
  post('FTKJWLHYPT/system/delSysFleetUser', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          uuid,
          lastModifier: store.state.user.USR_CODE_DX_H,
          version: String(version)
        }
      }
    }
  })
//编辑用户账号
export const editSysFleetUser = ({
  usrCode,
  usrName,
  usrStatus,
  version,
  uuid, //必填
  usrCellphone,
  usrEmail,
  remark
}) =>
  post('/FTKJWLHYPT/system/editSysFleetUser', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          usrCode,
          usrName,
          usrCellphone,
          usrEmail,
          usrStatus,
          remark,
          lastModifier: store.state.user.USR_CODE_DX_H,
          version: String(version),
          fltUuid: store.state.user.FLT_UUID_DX_H,
          uuid
        }
      }
    }
  })
//密码重置
export const resetSysUserpwd = ({ uuid, version }) =>
  post('/FTKJWLHYPT/system/resetSysFleetUserPassWord', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          uuid,
          lastModifier: store.state.user.USR_CODE_DX_H,
          version: String(version)
        }
      }
    }
  })

/**
 * 修改密码
 * @param uuid
 * @param password
 * @returns {Promise | Promise<unknown>}
 */
export const editPassword = ({ uuid, old, password }) =>
  post('/FTKJWLHYPT/system/editPassword', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          uuid,
          odlPassword: setMd5(old),
          usrPassword: setMd5(password)
        }
      }
    }
  })

export const editPasswordJson = data => {
  var { uuid, old, password } = JSON.parse(data)
  return post('/FTKJWLHYPT/system/editPassword', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          uuid,
          odlPassword: setMd5(old),
          usrPassword: setMd5(password)
        }
      }
    }
  })
}
